package com.lagou.edu.service;

import java.util.Date;


import org.springframework.beans.factory.annotation.Autowired;


import com.lagou.edu.dao.CodeDao;
import com.lagou.edu.pojo.LagouAuthCode;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.data.domain.Example;



@Service
public class CodeServiceImpl implements CodeService {

    @Autowired
    private CodeDao codeDao;

    @Override
    public Boolean codeSave(String email,String code) {
        LagouAuthCode lagouAuthCode = new LagouAuthCode();
        lagouAuthCode.setEmail(email);
        lagouAuthCode.setCode(code);
        Date date=new Date();
        Date date1=new Date(date.getTime()+10*60*1000);
        lagouAuthCode.setCreatetime(date);
        lagouAuthCode.setExpiretime(date1);
        LagouAuthCode save = codeDao.save(lagouAuthCode);
        if (save!=null){
            return true;
        }
        return false;

    }

    @Override
    public LagouAuthCode findOne(Example example) {
        try{
            return (LagouAuthCode)codeDao.findOne(example).get();
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }

}
